<template>
<a @click="downloadImg" href="#">点击下载</a>
</template>
<script>
import axios from "axios";
export default {
  name: "DownloadImg",
  methods: {
    downloadImg() {
      axios
        .post(
          "http://localhost:8000/api/download",
          {
            url:
              "https://www.ebay.cn/newcms/data/art_attach/image/20210326170525844.jpg",
          },
          {
            responseType: "blob", //指定返回数据的格式为blob
          }
        )
        .then((res) => {
          let data = res.data;
          let url = window.URL.createObjectURL(new Blob([data]));
          let link = document.createElement("a");
          link.style.display = "none";
          link.href = url;
          link.setAttribute("download", "test.png");
          document.body.appendChild(link);
          link.click();
        });
    },
  },
};
</script>